$(function () {
    var clent_id = "703832578";
    var redirectUri = "http://wap.soolife.cn/view/account/login_sina.html";
    var sinaloginUri = "http://wap.soolife.cn/server/sinalogin.php";
//初始构造请求
    if (window.location.search.indexOf("code=") == -1) {
        // 1 获取access_token
        var path = 'https://api.weibo.com/oauth2/authorize?';
        var queryParams = ['client_id=' + clent_id,
            'response_type=code',
            'redirect_uri=' + redirectUri];

        var query = queryParams.join('&');
        var url = path + query;
        window.location.href = url;
    }
    else {
        // 2. 如果用户同意授权，页面跳转至 YOUR_REGISTERED_REDIRECT_URI/?code=CODE
        var code = getUrlParam("code");
        //向服务端传输access_token及openid参数
        $.ajax({
            type: "GET", url: sinaloginUri + "?code=" + code
        }).done(function (res) {
            var response = JSON.parse(res);
            var userinfo = {typeid: 3, openid: response.id, name: response.name};
            // 验证用户信息
            var _verfiyAccountModel = new verfiyAccountModel();
            _verfiyAccountModel.verifyAccount(userinfo);
        });
    }
})
